package com.zhonglz.service.impl;

import java.util.HashMap;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.zhonglz.commons.base.BaseService;
import com.zhonglz.model.SysMenu;
import com.zhonglz.service.SysMenuService;
import com.zhonglz.util.tools.ObjectUtils;

/***
 * SysMenuServiceImpl  系统菜单信息接口实现
 * @author zhonglz saxon
 * @date 2021年7月6日
 */
@Service
@Transactional
public class SysMenuServiceImpl extends BaseService implements SysMenuService{
	
	private static Logger logger = LoggerFactory.getLogger(SysMenuServiceImpl.class);

	@Override
	public List<SysMenu> getChildMenuListByMenuNo(String menuNo) {
		
		return sysMenuMapper.getChildMenuListByMenuNo(menuNo);
	}

	@Override
	public List<SysMenu> getAllMenuByAll() {
		return sysMenuMapper.getAllMenuByAll();
	}

	@Override
	public List<SysMenu> getMenuListByParams(HashMap<String, Object> params) {
		return sysMenuMapper.getMenuListByParams(params);
	}

	@Override
	public boolean updateMenu(SysMenu menu) {
		return sysMenuMapper.updateByPrimaryKeySelective(menu) > 0 ? true : false;
	}

	@Override
	public boolean deleteMenu(String menuId) {
		return sysMenuMapper.deleteByPrimaryKey(menuId) > 0 ? true : false;
	}

	@Override
	public boolean insertMenu(SysMenu menu) {
		return sysMenuMapper.insert(menu) > 0 ? true : false;
	}

	/***
	 * 生成菜单编号
	 * @param menuParentNo 父编号
	 * @return
	 */
	@Override
	public String createMenuNo(String menuParentNo) {
		String retMenuNO = "";
		if(ObjectUtils.isNotEmpty(menuParentNo)){
			//查询出父级菜单的编号，一级
			List<SysMenu> list = sysMenuMapper.getChildMenuListByMenuNo(menuParentNo);
			retMenuNO = menuParentNo+"0"+(list.size()+1);
		}else{
			//先查询出所有的一级菜单
			int count = sysMenuMapper.getOneMenuListByCount()+1;
			retMenuNO = "0"+count;
		}
		return retMenuNO;
	}

	/***
	 * 生成父级菜单编号组
	 * @param menuParentNo 父编号
	 * @return
	 */
	@Override
	public String createMenuParentNos(String menuParentNo,String menuNo) {
		String retParentNos = "";
		SysMenu menuInfo = sysMenuMapper.selectMenuInfoByMenuNo(menuParentNo);
		if(menuInfo.getMenuType() == 1){
			retParentNos = menuInfo.getMenuNo() + "," + menuNo + ",";
		}else{
			retParentNos = menuInfo.getMenuParentNos() + menuNo + ",";
		}
		return retParentNos;
	}

}
